//
//  ImportPhoneView.swift
//  swiftProject
//
//  Created by ZhangSai on 2021/4/25.
//

import UIKit

class ImportPhoneView: UIView {

    typealias ImportPhoneBlock = () -> Void
    var importPhoneBlock : ImportPhoneBlock!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.addSubview(self.selectCountryCodeBrn)
        self.addSubview(self.importAccount)
        self.addSubview(self.verticalLineView)
        self.addSubview(self.placeholderView)
        self.addSubview(self.lineView)

        self.selectCountryCodeBrn.snp.makeConstraints { (make) in
            make.width.equalTo(50)
            make.left.equalTo(self.snp.left).offset(0)
            make.bottom.equalTo(self.snp.bottom).offset(-5)
            make.top.equalTo(self.snp.top).offset(0)
        }
        self.placeholderView.snp.makeConstraints { (make) in
            make.right.equalTo(self.selectCountryCodeBrn.snp.right).offset(0)
            make.bottom.equalTo(self.snp.bottom).offset(-8)
            make.width.equalTo(5.5)
            make.width.equalTo(5.5)
        }
        self.verticalLineView.snp.makeConstraints { (make) in
            make.left.equalTo(self.selectCountryCodeBrn.snp.right).offset(5)
            make.bottom.equalTo(self.snp.bottom).offset(-8)
            make.top.equalTo(self.snp.top).offset(5)
            make.width.equalTo(1)
        }
        self.importAccount.snp.makeConstraints { (make) in
            make.left.equalTo(self.verticalLineView.snp.right).offset(5)
            make.bottom.equalTo(self.snp.bottom).offset(-5)
            make.top.equalTo(self.snp.top).offset(0)
            make.right.equalTo(self.snp.right).offset(0)
        }
        self.lineView.snp.makeConstraints { (make) in
            make.left.equalTo(self.snp.left).offset(0)
            make.right.equalTo(self.snp.right).offset(0)
            make.bottom.equalTo(self.snp.bottom).offset(0)
            make.height.equalTo(1)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func clickSelectCountryCodeBrn() {
        if (importPhoneBlock != nil) {
            importPhoneBlock()
        }
    }
    
    func refreshUI(index:Int) {
        self.importAccount.placeholder = ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.hint_import_phone)
    }
    
    lazy var selectCountryCodeBrn : UIButton =  {
        let selectCountryCodeBrn = UIButton()
        selectCountryCodeBrn.setTitleColor(UIColor.init(hexString: "#3A3A3A"), for: .normal)
        selectCountryCodeBrn.titleLabel?.font = UIFont.systemFont(ofSize: 18)
        selectCountryCodeBrn.addTarget(self, action: #selector(clickSelectCountryCodeBrn), for: .touchUpInside)
        return selectCountryCodeBrn
    }()
    
    lazy var importAccount : UITextField =  {
        let importAccount = UITextField()
        importAccount.textColor = UIColor.init(hexString: "#333333")
        importAccount.font = UIFont.systemFont(ofSize: 18)
        importAccount.placeholder = ZslanguageTool.sharedLanguageTool().getIanguageWithKey(key: LanguageHeader.hint_import_phone)
        importAccount.keyboardType = .numberPad
        return importAccount
    }()
    
    lazy var lineView : UIView =  {
        let lineView = UIView()
        lineView.backgroundColor = UIColor.init(hexString: "#CACACA")
        return lineView
    }()
    
    lazy var verticalLineView : UIView =  {
        let verticalLineView = UIView()
        verticalLineView.backgroundColor = UIColor.init(hexString: "#CACACA")
        return verticalLineView
    }()
    
    lazy var placeholderView : UIImageView =  {
        let placeholderView = UIImageView()
        placeholderView.image = UIImage.init(named: "login_interval")
        return placeholderView
    }()
    
}
